<template>
  <div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form :hide-required-asterisk="true" :status-icon="true">
        <el-radio v-model="row.deal_state" label="0">可读</el-radio>
        <el-radio v-model="row.deal_state" label="1">不可读</el-radio>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="addDigitalType()" size="mini"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-input
      class="input1"
      placeholder="请输入查询的交易信用记录ID"
      prefix-icon="el-icon-search"
      v-model="msg"
      clearable
    ></el-input>
    <el-button @click="selectUser()" class="btn">查询</el-button>
    <el-table :data="list" border style="width: 100%">
      <el-table-column
        prop="deal_record_id"
        label="交易信息记录ID"
        header-align="center"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="user_name"
        label="用户名"
        header-align="center"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="digital_name"
        label="数码名字"
        header-align="center"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="digital_type_name"
        label="数码类型"
        header-align="center"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="price"
        label="价格"
        header-align="center"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="deal_date"
        label="交易日期"
        header-align="center"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="deal_text"
        label="出售详情"
        header-align="center"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="deal_state"
        label="状态"
        header-align="center"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.deal_state === '0' ? '可读' : '不可读' }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        header-align="center"
        align="center"
        width="149"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            plain
            @click="handleEdit(scope.$index, scope.row)"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import http from '../api/index';
import util from '../util/index';
export default {
  data() {
    return {
      msg: '',
      list: [],
      row: [],
      dialogVisible: false,
    };
  },
  mounted() {
    http
      .getDealMsg({
        pages: 1,
      })
      .then((r) => {
        console.log(r);
        this.list = r.data;
        ('');
        for (let i = 0; i < this.list.length; i++) {
          this.list[i].deal_state = this.list[i].deal_state + '';
        }
      });
  },
  methods: {
    // 查询
    selectUser() {
      var res = /^[0-9]{1,n}$ /;
      console.log(this.msg);
      if (this.msg === '') {
        http
          .getDealMsg({
            pages: 1,
          })
          .then((r) => {
            console.log(r);
            this.list = r.data;
            ('');
            for (let i = 0; i < this.list.length; i++) {
              this.list[i].deal_state = this.list[i].deal_state + '';
            }
          });
      }

      //匹配数字
      // else if(!res.test(this.msg)){
      //   alert('请正确输入交易ID的值')
      // }
      else {
        http
          .dealSelect({
            deal_record_id: this.msg,
          })
          .then((res) => {
            console.log(res);
            this.list = res.data.data;
              if(this.list.length===0){
             alert('请正确输入交易ID的值')
          }
          });
        
      }
    },
    handleEdit(index, row) {
      this.dialogVisible = true;
      this.row = row;
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
  },
};
</script>
<style scoped>
.el-input {
  width: 400px;
  margin-bottom: 30px;
}
.btn{
  margin-bottom: 30px;
}
</style>